﻿using Hotel_Project.HotelForm;
using Hotel_Project.Tools.MySqlData_Helps;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Hotel_Project.BIZ
{
    public class Vip_Form_Jjh
    {
        //增加按钮
        public void Vip_Form_AddButtom (params string[] str){
            try
            {
                Dao_MySql_Jjh.Execut($"insert into urse_vip values({Convert.ToInt32(str[0])},'{str[1]}','{str[2]}','{str[3]}',{str[4]},'{str[5]}','{str[6]}','{str[7]}','{str[8]}','{str[9]}','{str[10]}',{str[11]},'{str[12]}','{str[13]}',{Convert.ToDouble(str[14])},{Convert.ToDouble(str[15])},{Convert.ToInt32(str[16])},{Convert.ToInt32(str[17])})");
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2146233033)
                {
                    MessageBox.Show("增加重复");
                }
                MessageBox.Show("" + ex.HResult);
            }
        }
        //删除按钮
        public void Vip_Form_DelButtom (int index){
            try
            {
                int paper = Dao_MySql_Jjh.Execut($"delete from urse_vip where Vip_CardId = {index}");
                if (paper!=0)
                {
                    MessageBox.Show("删除成功!");
                }else MessageBox.Show("删除失败!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex.HResult);
            }
        }
        //保存按钮
        public void Vip_Form_SaveButtom (params string[] str)
        {
            try
            {
                int paper = Dao_MySql_Jjh.Execut(
                $"update urse_vip set Name='{str[1]}',Sex='{str[2]}',DateOfBirth='{str[3]}'," +
                $"PhoneNumber='{str[4]}',Site='{str[5]}',CardType='{str[6]}',State='{str[7]}',Start_Data='{str[8]}',End_Data='{str[9]}',DocumentType='{str[10]}'," +
                $"Document_Number='{str[11]}',Work_Unit='{str[12]}',Notes='{str[13]}'," +
                $"Accumulate_Consumption={Convert.ToDouble(str[14])},Accumulate_Recharge={Convert.ToDouble(str[15])},Consumption_Count={Convert.ToInt32(str[16])},Integral={Convert.ToInt32(str[17])}" +
                $" where Vip_CardId={Convert.ToInt32(str[0])}");
                if (paper != 0)
                {
                    MessageBox.Show("修改成功!");
                }
                else MessageBox.Show("修改失败!");
            }
            catch (Exception ex){
                MessageBox.Show("" + ex.HResult);
            }
            
        }

        public void Vip_Form_Locad(int id,Updata_Vip_jjh form) {
            foreach (DataRow item in Dao_MySql_Jjh.Read_Ececut($"SELECT * FROM urse_vip where Vip_CardId={id}").Tables[0].Rows)
            {
                form.textBox1.Text = item[0].ToString();
                form.textBox2.Text = item[1].ToString();
                form.comboBox1.SelectedIndex = form.comboBox1.Items.IndexOf(item[2].ToString());
                form.dateTimePicker1.Text = item[3].ToString();
                form.textBox3.Text = item[4].ToString();
                form.textBox4.Text = item[5].ToString();    
                form.comboBox3.SelectedIndex = form.comboBox3.Items.IndexOf(item[6].ToString());
                form.comboBox4.SelectedIndex = form.comboBox4.Items.IndexOf(item[7].ToString());
                form.dateTimePicker2.Text = item[8].ToString(); 
                form.dateTimePicker3.Text = item[9].ToString(); 
                form.comboBox7.SelectedIndex = form.comboBox7.Items.IndexOf(item[10].ToString());
                form.textBox5.Text = item[11].ToString();
                form.textBox6.Text = item[12].ToString();
                form.textBox7.Text = item[13].ToString();   
                form.textBox8.Text = item[14].ToString();   
                form.textBox9.Text = item[15].ToString();   
                form.textBox10.Text = item[16].ToString();
                form.textBox11.Text = item[17].ToString(); 
            }
        }
    }
}
